package org.deltaset.meta.internal;

import org.deltaset.meta.MetaActionHandler;
import org.deltaset.meta.MetaEntry;
import org.deltaset.meta.MetaHandlerFactory;
import org.deltaset.meta.MetaHandlerFactoryBuilder;
import org.deltaset.meta.extension.CatalogProvider;
import org.deltaset.meta.extension.OptionBuilderProvider;
import org.deltaset.meta.extension.RepositoryProvider;
import org.deltaset.meta.internal.mockmeta.RepositoryProviderImpl;
import org.deltaset.meta.internal.mockmeta.web.OptionBuilderProviderImpl;

/**
 *
 * @author dmakariev
 */
public final class MetaHandlerHelper {

    private MetaHandlerHelper() {
    }

    public static MetaActionHandler createMetaActionHandler() {

        final MetaHandlerFactory metaHandlerFactory = factoryBuilder();

        final MetaActionHandler actionHandler = metaHandlerFactory.createMetaActionHandler();
        return actionHandler;

    }

    public static MetaEntry createMetaEntry(final Class entityClass) {
        final MetaHandlerFactory metaHandlerFactory = factoryBuilder();

        final MetaEntry metaEntry = metaHandlerFactory.createMetaEntry(entityClass);
        return metaEntry;
    }

    private static MetaHandlerFactory factoryBuilder() {
        /*
        mustBeConfigured(repositoryProvider, RepositoryProvider.class);
        mustBeConfigured(optionBuilderProvider, OptionBuilderProvider.class);
        mustBeConfigured(catalogProvider, CatalogProvider.class);
         * */
        final String defaultCatalogResourcePath = "defaultCatalogResourcePath";
        final String defaultUnsupportedTemplateSrc = "defaultUnsupportedTemplateSrc";
        final String metaType = "metaType";
        final CatalogProvider catalogProvider = new DefaultCatalogProvider(defaultCatalogResourcePath, defaultUnsupportedTemplateSrc, metaType);
        final RepositoryProvider repositoryProvider = new RepositoryProviderImpl();
        final OptionBuilderProvider optionBuilderProvider = new OptionBuilderProviderImpl();
        final MetaHandlerFactoryBuilder builder = MetaHandlerFactoryBuilder.newBuilder();
        builder.provider(catalogProvider).provider(repositoryProvider).provider(optionBuilderProvider);
        final MetaHandlerFactory metaHandlerFactory = builder.build();
        return metaHandlerFactory;
    }
}
